﻿using System;
using System.Collections.Generic;
using System.Linq;
using UcAsp.Net.Model;

namespace UcAsp.Net.NOSQLDAL
{
    public class ArticlesPageDAL : UcAsp.Net.IDAL.IArticlesPageDAL
    {
        public List<ArticlesPage> GetArticlesPage()
        {
            return STSData.GetInstance.Select<Model.ArticlesPage>();
        }

        public ArticlesPage Insert(ArticlesPage model)
        {
            long key;
            Model.ArticlesPage lastrow = STSData.GetInstance.LastRow<Model.ArticlesPage>(out key);
            model.ID = Convert.ToInt32(key.ToString()) + 1;
            STSData.GetInstance.Insert<Model.ArticlesPage>(model.ID, model);
            return model;
        }

        public ArticlesPage GetArticlesPageByPageID(int artclesid, int pageid)
        {
            return GetArticlesPage().FirstOrDefault(o => o.ArticlesID == artclesid & o.PageID == pageid);
        }

        public List<ArticlesPage> GetArticlesPageByArticlesID(int artclesid)
        {
            return GetArticlesPage().Where(o => o.ArticlesID == artclesid).ToList();
        }

        public ArticlesPage GetArticlesPageByID(int id)
        {
            return GetArticlesPage().FirstOrDefault(o => o.ID == id);
        }

        public ArticlesPage Update(ArticlesPage model)
        {
            STSData.GetInstance.Update<Model.ArticlesPage>(model.ID, model);
            return model;
        }

        public bool Delete(int articleid)
        {
            STSData.GetInstance.Delete<Model.ArticlesPage>(articleid);
            return true;
        }
    }
}